<template>
  <div class="incomeDat">
    <div class="contentTopTitle">
      <div class="fl">
        <div class="title">收入日账通报</div>
      </div>
    </div>
    <div>
      <div>
        <el-form
          :inline="true"
          :model="form"
          label-width="70px"
          class="formList"
        >
          <el-form-item label="区域">
            <dx-cascader :area_id.sync="form.areaId" ref="cascader" />
          </el-form-item>
          <el-form-item label="账期" v-show="flag == 1">
            <el-date-picker
              v-model="form.time"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="账期" v-show="flag == 2 || flag == 3">
            <el-date-picker
              v-model="form.time2"
              type="month"
              placeholder="选择日期"
              value-format="yyyy-MM"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="还原标记" style="width: 18%">
              <el-select v-model="form.isActual">
                 <el-option v-for="(it, index) in acctual" :label="it.label" :value="it.value" :key="index"></el-option>
              </el-select>
          </el-form-item>
          <el-form-item class="btnBox" style="width: 30%">
            <el-button size="small" type="primary" @click="search"
              >查询</el-button
            >
            <el-button
              size="small"
              style="margin-left: 10px"
              type="orange"
              @click="exportModal"
              >导出</el-button
            >
            <el-button v-show="flag == 2 || flag == 3" size="small" type="orange" @click="getPdf(flag == '2' ? '#pdfDom' : '#pdfDom1')"
              >导出PDF</el-button
            >
          </el-form-item>
        </el-form>
      </div>

      <div class="content">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="收入日账报表" name="first">
            <tab1 :paramsObj="info" ref="tab1"></tab1>
          </el-tab-pane>
          <el-tab-pane label="基本面收入" name="second">
            <tab2 :paramsObj="info1" ref="tab2"></tab2>
          </el-tab-pane>
          <el-tab-pane label="码号级收入" name="third">
            <tab3 :paramsObj="info2" ref="tab3"></tab3>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>

<script>
import prefixAPI from "@/api/prefixAPI";
import { getCookie } from "@/common/js/cookie";
import { getSessionStorage } from "@/common/js/storage";
import { $budgetAPI } from "@/api";
import tab1 from "./incomeDay-tab1";
import tab2 from "./incomeDay-tab2";
import tab3 from "./incomeDay-tab3";
export default {
  name: "incomeDay",
  data() {
    return {
      htmlTitle:'基本面收入',
      form: {
        time: "",
        time2: "",
        areaId: "",
        resourceId: false,
        isActual: 0,
      },
      activeName: "first",
      tableData1: [],
      tableData2: [],
      colDefList1: [],
      colDefList2: [],
      info: {},
      info1: {},
      info2: {},
      paramsObj: {},
      flag: 1,
      acctual: [
        {
          label: '上期还原',
          value: 0
        },
        {
          label: '上期实际',
          value: 1
        },
      ]
    };
  },
  components: {
    tab1,
    tab2,
    tab3,
  },
  mounted() {
    let that = this;
    that.accountInfo = JSON.parse(getSessionStorage("accountInfo"));
    $budgetAPI.incomeDailyTime(
      {},
      (res) => {
        if (res || res.code == 0) {
          that.form.time =
            res.content.substring(0, 4) +
            "-" +
            res.content.substring(4, 6) +
            "-" +
            res.content.substring(6, 8);
          that.info = {
            time: res.content,
            areaId: that.form.areaId
              ? that.form.areaId
              : that.accountInfo.areaId,
              isActual: that.form.isActual 
          };
          // that.init();
          that.$refs.tab1.init(that.info);
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },
  methods: {
    search() {
      let that = this,
        params = {
          time: that.form.time,
          areaId: that.form.areaId ? that.form.areaId : that.accountInfo.areaId,
          isActual: that.form.isActual
          
        };
      if (that.flag == 1) {
        that.info = params;
        that.$refs.tab1.init(params);
      }
      if (that.flag == 2) {
        params.time = that.form.time2;
        that.info1 = params;
        that.$refs.tab2.init(params);
      }
      if (that.flag == 3) {
        params.time = that.form.time2;
        that.info1 = params;
        that.$refs.tab3.init(params);
      }
    },
    exportModal() {
      var that = this,
        token = getCookie("token");

      var obj = {
        areaId: that.form.areaId ? that.form.areaId : that.accountInfo.areaId,
        acctDay: "",
        acctMonth: "",
      };

      if (that.flag == 1) {
        //  obj.areaId = that.form.areaId;
        obj.acctDay = that.form.time;
        window.location.href =
          prefixAPI.hp +
          "/api/dailyAccountReport/export?areaId=" +
          obj.areaId +
          "&acctDay=" +
          that.form.time.replace(/-/g, "") +
          "&isActual=" + that.form.isActual + 
          "&token=" +
          token;
      }
      if (that.flag == 2) {
        //   obj.areaId = that.form.areaId;
        obj.acctDay = that.form.time;
        window.location.href =
          prefixAPI.hp +
          "/api/dailyAccountReport/exportIncomeDataList?areaId=" +
          obj.areaId +
          "&acctMonth=" +
          that.form.time2.replace(/-/g, "") +
          "&isActual=" + that.form.isActual + 
          "&type=1" +
          "&token=" +
          token;
      }
      if (that.flag == 3) {
        // obj.areaId = that.form.areaId;
        obj.acctDay = that.form.time;
        window.location.href =
          prefixAPI.hp +
          "/api/dailyAccountReport/exportIncomeDataList?areaId=" +
          obj.areaId +
          "&acctMonth=" +
          that.form.time2.replace(/-/g, "") +
          "&isActual=" + that.form.isActual + 
          "&type=2" +
          "&token=" +
          token;
      }
    },
    init(obj) {
      // that.paramsObj = obj;
    },
    handleClick(tab, event) {
      let that = this,
        params = {
          time: that.form.time,
          areaId: that.form.areaId ? that.form.areaId : that.accountInfo.areaId,
          isActual: that.form.isActual 
        };
      if (tab.name == "first") {
        params.flag = 1;
        that.flag = 1;
        that.info = params;
        that.$refs.tab1.init(params);
       
      }
      if (tab.name == "second") {
        params.flag = 2;
        that.flag = 2;
        that.form.time2 = params.time.substring(0, 7);
        params.time = params.time.substring(0, 7);
        that.info1 = params;
        that.$refs.tab2.init(params);
        that.htmlTitle = '基本面收入' 
      }
      if (tab.name == "third") {
        params.flag = 3;
        that.flag = 3;
        that.form.time2 = params.time.substring(0, 7);
        params.time = params.time.substring(0, 7);
        that.info2 = params;
        that.$refs.tab3.init(params);
        that.htmlTitle = '码号级收入'
      }
      that.init(params);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>